package palmtop.com.palmtop.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.beardedhen.androidbootstrap.AwesomeTextView;

import org.xutils.x;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import palmtop.com.palmtop.R;
import palmtop.com.palmtop.model.Taskgrid;
import palmtop.com.palmtop.util.Config;
import palmtop.com.palmtop.util.FuncUtil;

public class ShowtaskgriddetailActivity extends BaseActivity {

    @BindView(R.id.mtitle)
    TextView mtitle;
    @BindView(R.id.taskname)
    AwesomeTextView taskname;
    @BindView(R.id.taskaddress)
    AwesomeTextView taskaddress;
    @BindView(R.id.longitude)
    AwesomeTextView longitude;
    @BindView(R.id.latitude)
    AwesomeTextView latitude;
    @BindView(R.id.taskcontent)
    AwesomeTextView taskcontent;
    /*@BindView(R.id.receivername)
    AwesomeTextView receivername;*/
    @BindView(R.id.zphoto1)
    ImageView zphoto1;
    @BindView(R.id.zphoto2)
    ImageView zphoto2;
    @BindView(R.id.zphoto3)
    ImageView zphoto3;
    @BindView(R.id.zphoto4)
    ImageView zphoto4;
    @BindView(R.id.footBtn)
    Button footBtn;
    Taskgrid taskgrid;
    @BindView(R.id.lookmapBtn)
    Button lookmapBtn;

    MyApplication app;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_showtaskgriddetail, Config.toptitle, 1);
        ButterKnife.bind(this);
        app = (MyApplication) getApplication();
        app.addActivity(ShowtaskgriddetailActivity.this);
        app.addActivityList(ShowtaskgriddetailActivity.this);
        initView();
    }

    private void initView() {
        mtitle.setText("任务详情");
        footBtn.setText("查看分派情况");
        taskgrid = (Taskgrid) getIntent().getSerializableExtra("taskgrid");
        if (taskgrid != null) {
            taskname.setText(taskgrid.getTaskname());
            taskaddress.setText(taskgrid.getTaskaddress());
            longitude.setText(taskgrid.getLongitude());
            latitude.setText(taskgrid.getLatitude());
//            receivername.setText(taskgrid.getReceivername());
            taskcontent.setText(taskgrid.getTaskcontent());
            if (taskgrid.getPhoto1() != null && !taskgrid.getPhoto1().equals("")) {
                x.image().bind(zphoto1, Config.IMG_URL + taskgrid.getPhoto1());
                FuncUtil.clickShowBigPic(Config.IMG_URL + taskgrid.getPhoto1(), zphoto1, ShowtaskgriddetailActivity.this);
            }
            if (taskgrid.getPhoto2() != null && !taskgrid.getPhoto2().equals("")) {
                x.image().bind(zphoto2, Config.IMG_URL + taskgrid.getPhoto2());
                FuncUtil.clickShowBigPic(Config.IMG_URL + taskgrid.getPhoto2(), zphoto2, ShowtaskgriddetailActivity.this);
            }
            if (taskgrid.getPhoto3() != null && !taskgrid.getPhoto3().equals("")) {
                x.image().bind(zphoto3, Config.IMG_URL + taskgrid.getPhoto3());
                FuncUtil.clickShowBigPic(Config.IMG_URL + taskgrid.getPhoto3(), zphoto3, ShowtaskgriddetailActivity.this);
            }
            if (taskgrid.getPhoto4() != null && !taskgrid.getPhoto4().equals("")) {
                x.image().bind(zphoto4, Config.IMG_URL + taskgrid.getPhoto4());
                FuncUtil.clickShowBigPic(Config.IMG_URL + taskgrid.getPhoto4(), zphoto4, ShowtaskgriddetailActivity.this);
            }

        }
    }

    @OnClick(R.id.footBtn)
    public void onViewClicked() {
        Intent i = new Intent();
        i.putExtra("taskgrid", taskgrid);
        i.setClass(this, ProcesstaskActivity.class);
        startActivity(i);
    }

    @OnClick(R.id.lookmapBtn)
    public void onlookmapClicked() {
        Intent i = new Intent();
        if (!TextUtils.isEmpty(taskgrid.getLatitude())) {
            i.putExtra("latitude", taskgrid.getLatitude());
        }
        if (!TextUtils.isEmpty(taskgrid.getLongitude())) {
            i.putExtra("longitude", taskgrid.getLongitude());
        }
        i.setClass(this, LookmapActivity.class);
        startActivityForResult(i, 1);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
    }

}
